package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.stark.riddle.lib.model.db.RiddleDaoHelperManager;

import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.SayingKindAdapter;
import flc.ast.databinding.ActivitySayingKindBinding;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.inf.IRetCallback;

public class SayingKindActivity extends BaseAc<ActivitySayingKindBinding> {

    private SayingKindAdapter kindAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_saying_kind;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivSayingKindBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvKindList.setLayoutManager(new GridLayoutManager(mContext, 2));
        kindAdapter = new SayingKindAdapter();
        mDataBinding.rvKindList.setAdapter(kindAdapter);
        kindAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        SelLevelActivity.type = 1;
        SelLevelActivity.kindName = kindAdapter.getItem(position);
        startActivity(SelLevelActivity.class);
    }

    @Override
    protected void initData() {
        RiddleDaoHelperManager.getSayingDbHelper().getKinds(new IRetCallback<List<String>>() {
            @Override
            public void onResult(List<String> result) {
                kindAdapter.setList(result);
            }
        });
    }
}